package com.xhwl.data.util;

import com.xhwl.common.utils.StringUtils;

import java.util.regex.Pattern;

/**
 * @Author: luyi
 * @Description:
 * @Date: Create in 14:49 2021/4/17
 */
public class ValidatorUtil {

    /**
     * 验证手机号
     */
    public static final String REGEX_MOBILE = "^(1[3-9]([0-9]{9}))$";

    /**
     * 验证邮箱
     */
    public static final String REGEX_EMAIL = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$";
    /**
     * 校验座机号码 数字和-
     */
    public static final String REGEX_TEL = "^[^0-9-]+$";

    public static boolean isMobile(String mobile) {
        return !StringUtils.isEmpty(mobile) && Pattern.matches(REGEX_MOBILE, mobile);
    }

    public static boolean isEmail(String email) {
        return !StringUtils.isEmpty(email) && Pattern.matches(REGEX_EMAIL, email);
    }

    public static boolean isPassword(String pwd){
        return !StringUtils.isEmpty(pwd) && (8 <= pwd.length() && pwd.length() <= 20) && !pwd.contains(" ");
    }

    public static boolean isTel(String tel){
        Pattern pattern = Pattern.compile(REGEX_TEL);
        return !StringUtils.isEmpty(tel) && (5 <= tel.length() && tel.length() <= 12) && pattern.split(tel).length <= 1;
    }
}
